//
const express = require("express");
const app = express();
/*  */
const path = require("path"); //路径处理
const url = require("url");  //url处理
//console.log(url.parse("http://www.example.com/profile?name=barry"));
const publicPath = path.resolve(__dirname,"public");
//设置静态文件路径
app.use("/public",express.static(publicPath));
/*  */
//处理post请求的参数
const bodyParser = require("body-parser");
//cookie
const cookieParser = require("cookie-parser");
//  日志记录
const logger = require("morgan");
//解析post以application/x-www-form-urlencoded提交的数据
app.use(bodyParser.urlencoded({
    extended:false
}));
//解析post以application/json提交的数据
app.use(bodyParser.json());
//cookie解析
app.use(cookieParser());
//  日志记录
app.use(logger("short"));
/*  */
//
const baseConfig = require(`${__dirname}/baseConfig/config`);
//
const { setAppRouter } = require(`${__dirname}/router/index`);
const { sessionInit } = require(`${__dirname}/utils/session`);
//设置路由
setAppRouter(app);
//设置session
sessionInit(app);
//启动
app.listen(baseConfig.port,()=>{
    /* 
        localhost
        192.168.103.97
    */
    console.log(`启动了:http://localhost:${baseConfig.port}`);
});
